package com.demo.jsf;

import java.util.ArrayList;
import java.util.List;

import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

public class UserAction {
	private String username;
	private String password;

	public UserAction() {
		super();
	}

	public UserAction(String username, String password) {
		this.username = username;
		this.password = password;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String login() {
		return "success";
	}

	private List<UserAction> userList;

	public List<UserAction> getUserList() {
		if (userList == null) {
			userList = new ArrayList<UserAction>();
			userList.add(new UserAction("admin", "123"));
			userList.add(new UserAction("guest", "456"));
			userList.add(new UserAction("test", "abc"));
		}
		return userList;
	}

	private DataModel model;
	private int rowIndex = -1;

	public DataModel getUsers() {
		if (model == null) {
			model = new ListDataModel();
			model.setWrappedData(getUserList());
		}
		return model;
	}

	public int getSelectedRowIndex() {
		return rowIndex;
	}

	public String select() {
		rowIndex = model.getRowIndex();
		return "success";
	}
}
